package callnumber.gtdev5.com.photoVault.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.githang.statusbar.StatusBarCompat;
import com.gtdev5.geetolsdk.mylibrary.util.GsonUtils;
import com.gtdev5.geetolsdk.mylibrary.util.ToastUtils;

import java.io.File;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import callnumber.gtdev5.com.photoVault.R;
import callnumber.gtdev5.com.photoVault.adapter.ImagePagerAdapter;
import callnumber.gtdev5.com.photoVault.bean.ImageBean;
import callnumber.gtdev5.com.photoVault.widget.MutipleTouchViewPager;

public class ImagesVIewActivity extends AppCompatActivity {
    public static final String IMG_URL = "url";
    public static final String IMG_DATAS = "datas";
    public static final String IMG_POS = "pos";

    @BindView(R.id.vp_images)
    MutipleTouchViewPager vpImages;
    @BindView(R.id.tv_image_page)
    TextView tvImagePage;
    @BindView(R.id.iv_exit)
    ImageView ivExit;


    private ImagePagerAdapter pagerAdapter;
    private String url;
    private List<ImageBean> datas;
    private int positon = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.su_activity_images_view);

        if (Build.VERSION.SDK_INT > 19)
            StatusBarCompat.setStatusBarColor(this,
                    getResources().getColor(R.color.main_Color),
                    false);

        ButterKnife.bind(this);
        initView();
        initData();
    }


    protected void initView() {
        vpImages.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tvImagePage.setText(String.valueOf(position + 1) + File.separator + String.valueOf(pagerAdapter.getSize()));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        ivExit.setOnClickListener(view -> {
            finish();
        });
        //pagerAdapter = new ImagePagerAdapter(mContext,)


    }

    protected void initData() {
       // url = getIntent().getStringExtra(IMG_URL);
        positon = getIntent().getIntExtra(IMG_POS,0);
         datas = GsonUtils.getFromList(getIntent().getStringExtra(IMG_DATAS),ImageBean.class);
         if (datas==null||datas.size()<1){
             ToastUtils.showShortToast("参数错误");
             finish();
         }
        tvImagePage.setText("1"+File.separator+String.valueOf(datas.size()));

       /* url = "http://app.wm002.cn";
        datas = new ArrayList<>();
        datas.add(new Photo("upload\\\\rmt\\\\2018\\\\06\\\\08\\\\b08ef803a26541a5a8dd7954b05a8a9b.png"));
        datas.add(new Photo("upload\\\\rmt\\\\2018\\\\06\\\\08\\\\657c817de94142dc83dae18712a8a6be.png"));
        datas.add(new Photo("upload\\\\rmt\\\\2018\\\\06\\\\08\\\\24d7ed98d7954f8186011dcf60c48af7.png"));*/
        pagerAdapter = new ImagePagerAdapter(ImagesVIewActivity.this, datas);

        pagerAdapter.setListener(() -> {
            ImagesVIewActivity.this.finish();
        });
        vpImages.setAdapter(pagerAdapter);
        vpImages.setCurrentItem(positon<datas.size()?positon:0);
    }

}
